<?
/// --- AKCIÓ-VÉGREHAJTÁS ---

//AUTOMATIKUS AKCIÓK



// FELHASZNÁLÓI AKCIÓK
switch($_GET['act']){
	case 'buy':
		$from = new DataRowManager('buyanimals', (int)$_GET['id']);
		if($from->own()){
			$fromdata = $from->get("*");
			$ins = array(
				"id" => $fromdata['id'],
				"userid" => $fromdata['userid'],
				"type" => $fromdata['type'],
				"name" => $fromdata['name'],
				"image" => $fromdata['image'],
				"basehappy" => $fromdata['basehappy'],
				"weight" => "100",
				"foodendtime" => time()+$mainconf->get("foodtime"),
				"foodhappy" => $mainconf->get("foodhappy1")
			);
			if($userdata->getMoney()>$fromdata['price']){
			start_transaction();
				$userdata->decreaseMoney($fromdata['price']);
				DataRowManager::create('animals', $ins);
				$from->destroy();
			end_transaction();
			}
			refresh();
		}
		break;
}




///  --- OLDAL-ADATOK ELŐKÉSZÍTÉSE ---

// CONTENTS
//allatlista
	$a_list = new DataListManager('buyanimals', 'userid='.$_SESSION['userid']);
	$i=0;
	while($curr = $a_list->next_row()){
		$val =  array();
		
		//row start/end
		if($i % 2 == 0){
			$val['rowstart']='<tr>';
				if($i==$a_list->length-1){ // utsó, de páratlan
					$val['rowend'] = '<td>&nbsp;</td></tr>';
				}
		}
		else{
			$val['rowend']='</tr>';
		}
		
		//id
		$val['id']=$curr->get('id');
		
		//name
		$val['name']= $curr->get('name');
		
		//type
		$val['type']= $curr->get('type');
		
		//image
		$val['image']='template/images/'.$curr->get('type').$curr->get('image').'.jpg';
		
		//happy
		
		$val['jokedv']=$curr->get('basehappy');
		
		//price
		$val['price']=$curr->get('price');
		
		//buy
		if($userdata->getMoney()>$val['price']){
			$val['buy']='<a href="?act=buy&amp;id='.$val['id'].'" class="reszletlink">{buy}</a>';
		}
		else{
			$val['buy']='{buymoney}';
		}
		
		
		setContents('allatlista', $val);
		$i++;
	}

	

// OUTPUT




?>
